package com.kuangjia.boss;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@EnableSwagger2
@EnableCaching
@MapperScan("com.kuangjia.boss.localBOSS.**.mapper")
@SpringBootApplication()
@EnableScheduling
@EnableAsync
@ServletComponentScan //防sql注入
@EnableAspectJAutoProxy
public class KuangJiaApplication extends SpringBootServletInitializer {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(KuangJiaApplication.class, args);
        Environment env = application.getEnvironment();
        String applicationName = env.getProperty("spring.application.name");
        String port = env.getProperty("server.port");
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
//        log.info(buddha);
        log.info("\n" +
                        "\n" +
                        "\n" +
                        "\u001B[31m                                                          =================(♥◠‿◠)ﾉﾞ  乙己科技启动成功   ლ(´ڡ`ლ)ﾞ=======================    \n" +
                        "\u001B[32m                                                                   **        _     _      ________     _    __      ________        **                \n" +
                        "\u001B[33m                                                                  *****     \\ \\   / /    |________|   | |  / /     |________|     *****              \n" +
                        "\u001B[34m                                                                *********    \\ \\_/ /         | |      | |_/ /          | |       *********             \n" +
                        "\u001B[35m                                                                 *******       | |       _   | |      |  _ |       _   | |        *******             \n" +
                        "\u001B[36m                                                                  ****         | |      | |__| |      | | \\ \\     | |__| |         ****              \n" +
                        "\u001B[32m                                                                   *           |_|      |______|      |_|  \\_\\    |______|           *              \n" +
                        "\u001B[31m                                                          ============================================================================     \n" +
                        "\u001B[0m\n" +
                        "\n                                                                  ---------------------------------------------------------\n" +
                        "\t                                                                   Application '{}' is running! Access URLs:\n" +
                        "\t                                                                   Local:\t\thttp://localhost:{}\n" +
                        "\t                                                                   External:\thttp://{}:{}\n" +
                        "\t                                                                   API Doc:\thttp://{}:{}/doc.html\n" +
                        "                                                                  ----------------------------------------------------------\n" +
                        "                       " +
                        "                       ",

                applicationName, port, hostAddress, port, hostAddress, port);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(KuangJiaApplication.class);
    }

    static String buddha =
            "                         " +
                    "\n           _oo0oo_" +
                    "\n          o8888888o" +
                    "\n          88\" . \"88" +
                    "\n          (| -_- |)" +
                    "\n          0\\  =  /0" +
                    "\n        ___/`---'\\___" +
                    "\n      .' \\\\|     |// '." +
                    "\n     / \\\\|||  :  |||// \\" +
                    "\n    / _||||| -:- |||||- \\" +
                    "\n   |   | \\\\\\  -  /// |   |" +
                    "\n   | \\_|  ''\\---/''  |_/ |" +
                    "\n   \\  .-\\__  '-'  __/-.  /" +
                    "\n ___'. .'  /--.--\\  '. .'___" +
                    "\n\"\" '<  '.___\\_<|>_/___.' >' \"\"." +
                    "\n| | :  '- \\'.;\\_ /';.'/ - ' : | |" +
                    "\n\\  \\ '-.  \\_ __\\ /__ _/  .-' /  /" +
                    "\n========='-._____'-.=========" ;
}